package com.example.wechat.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class deviceTypeUtil {

    //获取设备类型
    public static String getType(String nameChar){
        Map<String,String> deviceTypeMap = new HashMap<>();
        deviceTypeMap.put("JZM","卷闸门");
        deviceTypeMap.put("DZMB","电子门匾");
        deviceTypeMap.put("DFT","电扶梯");
        deviceTypeMap.put("CZDT","垂直电梯");
        deviceTypeMap.put("GGDX","广告灯箱");
        deviceTypeMap.put("KFZX","客服中心");
        deviceTypeMap.put("AGM","售票机");
        deviceTypeMap.put("PIDS","PIDS屏幕");
        deviceTypeMap.put("GB","广播");
        deviceTypeMap.put("DZDY","电子导引");
        deviceTypeMap.put("ZJ","闸机");
        deviceTypeMap.put("KLYD","客流引导灯带");
        deviceTypeMap.put("ZNZM","智能照明");
        deviceTypeMap.put("ZNZM2","智能照明2");
        deviceTypeMap.put("FJ","风机");
        deviceTypeMap.put("PBM","屏蔽门");
        deviceTypeMap.put("CCTV","摄像头");
        deviceTypeMap.put("WG","温感报警器");
        deviceTypeMap.put("YG","烟感报警器");
        deviceTypeMap.put("YJSS","应急疏散灯");
        deviceTypeMap.put("YW","烟雾发生器");
        deviceTypeMap.put("DC","道岔转辙机");
        deviceTypeMap.put("XHJ","信号机");
        deviceTypeMap.put("GDDL","轨道电路");
        deviceTypeMap.put("XB","信标");
        deviceTypeMap.put("SDFJ","隧道风机");
        return deviceTypeMap.get(nameChar);
    }


    //根据设备类型获取对应的id，来进行对应配对
    public static Integer getPid(String nameChar){
        Map<String,Integer> deviceTypeMap = new HashMap<>();
        deviceTypeMap.put("JZM",1);
        deviceTypeMap.put("DZMB",2);
        deviceTypeMap.put("DFT",3);
        deviceTypeMap.put("CZDT",4);
        deviceTypeMap.put("GGDX",5);
        deviceTypeMap.put("KFZX",6);
        deviceTypeMap.put("AGM",7);
        deviceTypeMap.put("PIDS",8);
        deviceTypeMap.put("GB",9);
        deviceTypeMap.put("DZDY",10);
        deviceTypeMap.put("ZJ",11);
        deviceTypeMap.put("KLYD",12);
        deviceTypeMap.put("ZNZM",13);
        deviceTypeMap.put("ZNZM2",14);
        deviceTypeMap.put("FJ",15);
        deviceTypeMap.put("PBM",16);
        deviceTypeMap.put("CCTV",17);
        deviceTypeMap.put("WG",18);
        deviceTypeMap.put("YG",19);
        deviceTypeMap.put("YJSS",20);
        deviceTypeMap.put("YW",21);
        deviceTypeMap.put("DC",22);
        deviceTypeMap.put("XHJ",23);
        deviceTypeMap.put("GDDL",24);
        deviceTypeMap.put("XB",25);
        deviceTypeMap.put("SDFJ",26);
        return deviceTypeMap.get(nameChar);
    }

    // 提取字符串中只有字符串的部分
    private static String isAsciiLetter(String str) {
        return str.replaceAll("[^a-zA-Z].*$", "");
    }
    // 提取字符串中只有数字的部分
    public static String getNumeric(String str) {
        String regEx="[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }

    public static List getTypeList2(){
        List<JSONObject> jsonObjectList = new ArrayList<>();
        String json = "{\"list\":[{\"children\":[],\"id\":1,\"label\":{\"text\":\"卷闸门\",\"status\":\"\"}},{\"children\":[],\"id\":2,\"label\":{\"text\":\"电子门匾\",\"status\":\"\"}},{\"children\":[],\"id\":3,\"label\":{\"text\":\"电扶梯\",\"status\":\"\"}},{\"children\":[],\"id\":4,\"label\":{\"text\":\"垂直电梯\",\"status\":\"\"}},{\"children\":[],\"id\":5,\"label\":{\"text\":\"广告灯箱\",\"status\":\"\"}},{\"children\":[],\"id\":6,\"label\":{\"text\":\"客服中心\",\"status\":\"\"}},{\"children\":[],\"id\":7,\"label\":{\"text\":\"售票机\",\"status\":\"\"}},{\"children\":[],\"id\":8,\"label\":{\"text\":\"PIDS屏幕\",\"status\":\"\"}},{\"children\":[],\"id\":9,\"label\":{\"text\":\"广播\",\"status\":\"\"}},{\"children\":[],\"id\":10,\"label\":{\"text\":\"电子导引\",\"status\":\"\"}},{\"children\":[],\"id\":11,\"label\":{\"text\":\"闸机\",\"status\":\"\"}},{\"children\":[],\"id\":12,\"label\":{\"text\":\"客流引导灯带\",\"status\":\"\"}},{\"children\":[],\"id\":13,\"label\":{\"text\":\"智能照明1\",\"status\":\"\"}},{\"children\":[],\"id\":14,\"label\":{\"text\":\"智能照明2\",\"status\":\"\"}},{\"children\":[],\"id\":15,\"label\":{\"text\":\"风机\",\"status\":\"\"}},{\"children\":[],\"id\":16,\"label\":{\"text\":\"屏蔽门\",\"status\":\"\"}},{\"children\":[],\"id\":17,\"label\":{\"text\":\"摄像头\",\"status\":\"\"}},{\"children\":[],\"id\":18,\"label\":{\"text\":\"温感报警器\",\"status\":\"\"}},{\"children\":[],\"id\":19,\"label\":{\"text\":\"烟感报警器\",\"status\":\"\"}},{\"children\":[],\"id\":20,\"label\":{\"text\":\"应急疏散灯\",\"status\":\"\"}},{\"children\":[],\"id\":21,\"label\":{\"text\":\"烟雾发生器\",\"status\":\"\"}},{\"children\":[],\"id\":22,\"label\":{\"text\":\"道岔转辙机\",\"status\":\"\"}},{\"children\":[],\"id\":23,\"label\":{\"text\":\"信号机\",\"status\":\"\"}},{\"children\":[],\"id\":24,\"label\":{\"text\":\"轨道电路\",\"status\":\"\"}},{\"children\":[],\"id\":25,\"label\":{\"text\":\"信标\",\"status\":\"\"}},{\"children\":[],\"id\":26,\"label\":{\"text\":\"隧道风机\",\"status\":\"\"}}]}";
        JSONObject jsonObject = JSONObject.parseObject(json);
        JSONArray dataArray = jsonObject.getJSONArray("list");
        for (Object o : dataArray) {
            jsonObjectList.add((JSONObject) o);
        }
        return jsonObjectList;
    }



    public static JSONArray getArray(){
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject00 = new JSONObject();
        jsonObject00.put("label","00");
        jsonObject00.put("value","第0");
        JSONObject jsonObject01 = new JSONObject();
        jsonObject01.put("label","01");
        jsonObject01.put("value","第1");
        JSONObject jsonObject02 = new JSONObject();
        jsonObject02.put("label","02");
        jsonObject02.put("value","第2");
        JSONObject jsonObject03 = new JSONObject();
        jsonObject03.put("label","03");
        jsonObject03.put("value","第3");
        JSONObject jsonObject04 = new JSONObject();
        jsonObject04.put("label","04");
        jsonObject04.put("value","第4");
        JSONObject jsonObject05 = new JSONObject();
        jsonObject05.put("label","05");
        jsonObject05.put("value","第5");
        JSONObject jsonObject06 = new JSONObject();
        jsonObject06.put("label","06");
        jsonObject06.put("value","第6");
        JSONObject jsonObject07 = new JSONObject();
        jsonObject07.put("label","07");
        jsonObject07.put("value","第7");
        JSONObject jsonObject08 = new JSONObject();
        jsonObject08.put("label","08");
        jsonObject08.put("value","第8");
        JSONObject jsonObject09 = new JSONObject();
        jsonObject09.put("label","09");
        jsonObject09.put("value","第9");

        jsonArray.add(jsonObject00);
        jsonArray.add(jsonObject01);
        jsonArray.add(jsonObject02);
        jsonArray.add(jsonObject03);
        jsonArray.add(jsonObject04);
        jsonArray.add(jsonObject05);
        jsonArray.add(jsonObject06);
        jsonArray.add(jsonObject07);
        jsonArray.add(jsonObject08);
        jsonArray.add(jsonObject09);

        return  jsonArray;
    }


    public static  List<JSONObject> search(List<JSONObject> logsList){
        Collections.sort(logsList, new Comparator<JSONObject>() {
            @Override
            public int compare(JSONObject o1, JSONObject o2) {
                if ((o1.getString("device_name").compareTo(o2.getString("device_name")))==0){
                    return -1;
                }
                return (o1.getString("device_name").compareTo(o2.getString("device_name")));
            }
        });
        return logsList;
    }



}
